package com.changgou.system.filter;

import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.Ordered;
import org.springframework.http.server.RequestPath;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

/**
 * Created by 柱子 on 2020/10/14 19:50   获取客户端访问URL
 */
@Component
public class UrlFilter implements GlobalFilter, Ordered {

    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        //获取客户端访问URL
        System.out.println("经过第二个过滤器");
        ServerHttpRequest request = exchange.getRequest();
        String path = request.getURI().getPath();
        // String host = request.getURI().getHost();
        // System.out.println("host"+host);
        System.out.println("URL: " + path);
        //放行
        return chain.filter(exchange);
    }

    //执行优先级
    public int getOrder() {
        return 2;
    }
}
